Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix error handling #481

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

fix error handling #481

wants to merge 1 commit into from

Conversation

lieff
Copy link
Contributor

@lieff lieff commented May 17, 2018

ctx can't be != NULL on error path, nvgDeleteInternal can return immediately (if (ctx == NULL) return;) without userPtr cleanup => "gl" can leak.

Copy link
Owner

@memononen memononen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! A couple of fixed still needed, though.

@@ -288,7 +288,11 @@ NVGcontext* nvgCreateInternal(NVGparams* params)
FONSparams fontParams;
NVGcontext* ctx = (NVGcontext*)malloc(sizeof(NVGcontext));
int i;
if (ctx == NULL) goto error;
if (ctx == NULL) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be (ctx->params is not set yet either):

if (ctx == NULL) {
	// Call renderer delete explicitly. Context is not initialized yet, so we cannot call nvgDeleteInternal() which usually calls the function.
	if (params->renderDelete != NULL)
		params->renderDelete(params->userPtr);
	return  NULL;
}

src/nanovg_gl.h Outdated
@@ -1590,7 +1590,6 @@ NVGcontext* nvgCreateGLES3(int flags)

error:
// 'gl' is freed by nvgDeleteInternal.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment

@lieff
Copy link
Contributor Author

lieff commented May 17, 2018

Updated)

@lieff
Copy link
Contributor Author

lieff commented May 30, 2018

Is changes good? Anything needed from my side?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants